package com.eclipse.e20200205_集合.map;


import java.util.HashMap;

class Student{
	String name;
	Integer age;
	Student(String name, Integer age){
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	
}

public class e_hashMap_key去重 {
	public static void main(String[] args) {
		
		HashMap<String,Integer> hm = new HashMap<>();
		hm.put("a",1);
		//已经存在相同的key,做的是一个修改操作
		hm.put("a", 2);
		System.out.println(hm);
		
		
		HashMap<Student,String> hm2 = new HashMap<>();
		hm2.put(new Student("张三",20), "北京");
		hm2.put(new Student("张三",20), "深圳");
		hm2.put(new Student("李四",20), "上海");
		System.out.println(hm2);
		
		
		
	}
}
